package net.nycjava.skylight1.dependencyinjection;

//TODO javadoc
class SingletonObjectSource<T> extends ObjectSource<T> {

    private T singleObject;

    private boolean dependenciesInjected;

    SingletonObjectSource(T aSingleObject, boolean isConstant) {
        singleObject = aSingleObject;
        dependenciesInjected = isConstant;
    }

    SingletonObjectSource(T aSingleObject) {
        this(aSingleObject, false);
    }

    @Override
    public T getObject(DependencyInjector injector) {
        if (!dependenciesInjected) {
            injector.injectDependenciesForClassHierarchy(singleObject);
            dependenciesInjected = true;
        }
        return singleObject;
    }

}